package com.stu.design_patterns.proxy._03_dynamic_proxy_cglib;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

public class PersonInterceptor implements MethodInterceptor {
  private Object target;
  public PersonInterceptor(Object target) {this.target = target; }

  @Override
  public Object intercept(Object proxy, Method method, Object[] args, MethodProxy mp) throws Throwable {
    before();
    Object returnValue = method.invoke(target, args);
    after();
    return returnValue;
  }
  
  public void before() { System.out.println("饭前洗手"); }
  public void after() { System.out.println("饭后运动"); }
}
